<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增知识库类型')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content pt-md">
    <form class="form-horizontal" id="form-knowType-add">
        <div class="form-group">
            <input id="treeId" name="parentId" type="hidden" th:value="${knowBaseType?.id}"   />
            <label class="col-sm-3 control-label is-required">上级知识库类型：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" onclick="selectKnowBaseTypeTree()" id="treeName"
                           readonly="true"
                           th:value="${knowBaseType?.knowTypeName}" required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">知识库类型：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="knowTypeName" id="knowTypeName" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">显示排序：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="orderByNo" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="memo">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    var prefix = ctx + "gy/know_type";

    $("#form-knowType-add").validate({
        onkeyup: false,
        rules:{
            knowType:{
                remote: {
                    url: prefix + "/checkKnowBaseTypeUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "parentId": function() {
                            return $("input[name='parentId']").val();
                        },
                        "knowTypeName" : function() {
                            return $.common.trim($("#knowTypeName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            orderNum:{
                digits:true
            },
        },
        messages: {
            "knowTypeName": {
                remote: "知识库类型经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-knowType-add').serialize());
        }
    }


    function selectKnowBaseTypeTree() {
        var treeId = $("#treeId").val();
        if ($.common.isEmpty(treeId)) {
            $.modal.alertWarning("请先新增用户所选的知识库类型！");
            return;
        }
        var options = {
            title: '知识库类型选择',
            width: "380",
            url: prefix + "/selectKnowBaseTypeTree/" + treeId + "/0",
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }
</script>
</body>
</html>
